<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/cloudiary.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Cloudiary</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->
<link href="CSS/css.css" rel="stylesheet" type="text/css" />
</head>
<?php
  include('adminlock.php');
?>
<body>
<div id="container">
<div id="wrapper">

<div id="header">
<!-- InstanceBeginEditable name="header" -->
<div class="welcome">
<?php include('welcomeadmin.php'); ?>
</div>
<!-- InstanceEndEditable -->

<img src="Assets/cloud diary low-01(trans).png" alt="CloudDiary" width="75" height="45" style="padding:5px 10px;" /> <br />
</div>

<div id="main">
<div id="admin">
	<!-- InstanceBeginEditable name="Main" -->
  <?php  
    if($_SERVER["REQUEST_METHOD"] == "POST")
    { 
      $_SESSION['commentsview'] = $_POST['viewID'];
      $id = $_SESSION['commentsview'];	
    }
    else
    {
      if(isset($_SESSION['commentsview']))
      {
        $id = $_SESSION['commentsview'];
      }
      else{echo "Cannot apply session";}
    }
    $sql="SELECT * FROM post WHERE post_ID='$id'";
    $q1=mysql_query($sql);
    $fetch_q1=mysql_fetch_array($q1);
    
    $user_email=$fetch_q1['user_email'];
    echo "<p style='font-size:16px; font-weight:bold'>".$fetch_q1['post_topic']."</p>";
	echo "<p style='font-size:16px;'>".$fetch_q1['post']."</p>";
    echo "<br />"; 
    
    $sql_one="SELECT * FROM user WHERE user_email ='$user_email'";
    $q2=mysql_query($sql_one);
    $fetch_q2=mysql_fetch_array($q2);
  
  ?> 
  
    <br /> <br />
	<br /> <br />
	
	<table border="0" width="100%" height="5px" style="color:#999; font-size:11px">
	<tr>
	
	<td width="20%" align="center"> Posted By <?php echo $fetch_q2['user_name'];?> </td>
	<td width="20%" align="center"> Posted Date <?php echo $fetch_q1['post_date']; ?> </td>
	<td width="20%" align="center"> Posted Time <?php echo $fetch_q1['post_time']; ?> </td>
	<td width="20%" align="center"> Last Updated Date <?php echo $fetch_q1['post_edit_date']; ?> </td>
	<td width="20%" align="center"> Last Updated Time <?php echo $fetch_q1['post_edit_time']; ?> </td>
	</tr>
	</table>
    
    <p style="border-top:solid 1px #69F; width:100%"> &nbsp; </p>
    <br />
    
  <?php
    
    $single_page=3;
	$query="SELECT * FROM comment WHERE post_ID='$id'";
    $query_name=mysql_query($query);
    $count=mysql_num_rows($query_name);
    $total_pages=ceil($count/$single_page);
    
    if(isset($_GET['page']) && is_numeric($_GET['page']))
    {
      $obtain_page=$_GET['page'];
      if($obtain_page>0 && $obtain_page<=$total_pages)
      {
        $starting_page=($obtain_page-1)*$single_page;
        $ending_page=$starting_page+$single_page;
      }
      else
      {
        $starting_page=0;
        $ending_page=$starting_page+$single_page;
      }
    }
    else
    {
      $starting_page=0;
      $ending_page=$starting_page+$single_page;
    }        
    
	$q = $query . " LIMIT $starting_page,$single_page";
    $q=mysql_query($q);
    
?>
<div id="page">
<?php
	echo"<br /> <strong> &nbsp; Page: &nbsp;</strong>" ;
    for($a=1;$a<=$total_pages;$a++)
    { 
      echo"<a href='AdminComments.php?page=$a'>$a</a>"." | ";
    }
?>
</div>
<?php
    echo"</p>";
    
   if($count==0)
    {
     echo "No comments to show for this user";
    }
   
    for($a=$starting_page;$a<$ending_page;$a++)
    {
      if($a==$count){
      break;
      }
      
      while($data_fetch=mysql_fetch_array($q))
      { 
      ?>
        <table border="0" width="100%" align="center">
        <tr>
        <td width="25" rowspan="4">&nbsp;  </td>
        <td colspan="5">&nbsp;  </td> 
        <td width="25" rowspan="4">&nbsp;  </td>
        </tr>
        <?php
          $friend_email = $data_fetch['friend_email'];
          $sql_query1="SELECT user_name, user_email FROM user WHERE user_email='$friend_email'";
          $query1=mysql_query($sql_query1);
          $data_fetch1=mysql_fetch_array($query1);  
        ?>
        
        <tr> <td width="90" rowspan="2" style="border:solid 1px #69F; padding:2px;">
        <img src="display_photo.php?id=<?php echo $data_fetch1['user_email']; ?>" alt="User picture" width="90px" height="100px" />
        </td>
        <td width="21" rowspan="2" style="border-right:solid 1px #69F"> </td>
        <td height="134" colspan="2" > &nbsp; <?php echo $data_fetch['comment']; ?></td>
        
        <td align="right" width="150" rowspan="2">
          
          <form name="delete" action="SQL.php" method="POST" class="delete_button">
            <input type="hidden" name="query" value="<?php echo "DELETE FROM comment WHERE comment_ID='".$data_fetch['comment_ID']."'"; ?>"/>
			<input type="hidden" name="location" value="<?php echo "AdminComments.php"; ?>"/>
            <input type="image" src="Assets/buttonDelete.png" value="Delete" />
          </form>

        </td> </tr>
        <tr> 
        <td height="30px" align="center" style="color:#999; font-size:11px"> &nbsp; Posted on: <?php echo $data_fetch['comment_date']; ?></td>

        <td align="center" height="30px" style="color:#999; font-size:11px"> Posted by &nbsp; &nbsp; <?php echo $data_fetch1['user_name']; ?></td>
        </tr>
        <tr> <td colspan="5"  style="border-bottom:solid 1px #69F;">&nbsp;  </td> </tr>
        </table>
  
  <?php  
      echo"</tr>"; 
      echo"<br />";
      }
    }
    
    
  ?>
    
 </div>   
    <!-- InstanceEndEditable -->
</div>

</div>
</div>

<div id="footer">
<p align="center"> &copy; &nbsp; 2012 CloudDiary </p>
</div>
</body>
<!-- InstanceEnd --></html>
